<html>
<head><meta charset="utf-8"><title>Building core with PIC relocation model? · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Building.20core.20with.20PIC.20relocation.20model.3F.html">Building core with PIC relocation model?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="205797133"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Building%20core%20with%20PIC%20relocation%20model%3F/near/205797133" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> osa1 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Building.20core.20with.20PIC.20relocation.20model.3F.html#205797133">(Aug 03 2020 at 14:00)</a>:</h4>
<p>How do I build core for a specific target (wasm32-wasi and wasm32-unknown-emscripten in my case) with PIC relocation model? xargo can do it and I think it uses RUSTFLAGS env variable, but I don't know how to set this only when building the a specific library for a specific target.</p>



<a name="205801378"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Building%20core%20with%20PIC%20relocation%20model%3F/near/205801378" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> osa1 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Building.20core.20with.20PIC.20relocation.20model.3F.html#205801378">(Aug 03 2020 at 14:37)</a>:</h4>
<p>I currently do this:</p>
<div class="codehilite"><pre><span></span><code>diff --git a/src/librustc_target/spec/wasm32_base.rs b/src/librustc_target/spec/wasm32_base.rs
index 8423573b52d..fa9499b37a8 100644
--- a/src/librustc_target/spec/wasm32_base.rs
+++ b/src/librustc_target/spec/wasm32_base.rs
@@ -126,14 +126,7 @@ pub fn options() -&gt; TargetOptions {

         crt_objects_fallback: Some(CrtObjectsFallback::Wasm),

-        // This has no effect in LLVM 8 or prior, but in LLVM 9 and later when
-        // PIC code is implemented this has quite a drastric effect if it stays
-        // at the default, `pic`. In an effort to keep wasm binaries as minimal
-        // as possible we&#39;re defaulting to `static` for now, but the hope is
-        // that eventually we can ship a `pic`-compatible standard library which
-        // works with `static` as well (or works with some method of generating
-        // non-relative calls and such later on).
-        relocation_model: RelocModel::Static,
+        relocation_model: RelocModel::Pic,

         // When the atomics feature is activated then these two keys matter,
         // otherwise they&#39;re basically ignored by the standard library. In this
</code></pre></div>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>